//
//  ZTimeOutOrderTreatingVC.m
//  DistributorAB
//
//  Created by LZY on 2019/10/16.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZTimeOutOrderTreatingVC.h"
#import "BApplyForMoneySuccessView.h"//提交成功提示view
#import "ZTimeOutOrderAlertDealView.h"

@interface ZTimeOutOrderTreatingVC () <BApplyForMoneySuccessViewDelegate,ZTimeOutOrderAlertDealViewDelegate>
@property (nonatomic, strong) UITextField *tfName;//师傅姓名
@property (nonatomic, strong) UITextField *tfPhone;//联系电话
@property (nonatomic, strong) UITextView *tvResult;//处理结果

@end

@implementation ZTimeOutOrderTreatingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"处理中";
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    self.view.backgroundColor = kColorWithHex(0xf2f2f2);
    
    [self setupViewAction];
}
#pragma mark - 界面布局
- (void)setupViewAction{
    
    UIView *viewBg = [[UIView alloc] initWithFrame:CGRectMake(10, 19 + kNaviHeight, kScreen_Width - 20, 246)];
    viewBg.backgroundColor = kColorWithHex(0xffffff);
    [self.view addSubview:viewBg];
    
    UILabel *lblNotice = [[UILabel alloc] initWithFrame:CGRectMake(10, 11, viewBg.width - 20, 22)];
    lblNotice.text = @"给出回复:";
    lblNotice.font = [UIFont boldSystemFontOfSize:16];
    lblNotice.textColor = kColorWithHex(0x232620);
    [viewBg addSubview:lblNotice];
    
    UILabel *lblNoticeName = [[UILabel alloc] initWithFrame:CGRectMake(10, 38, 70, 42)];
    lblNoticeName.textColor = kColorWithHex(0x666666);
    lblNoticeName.font = [UIFont systemFontOfSize:14];
    lblNoticeName.text = @"师傅姓名:";
    [viewBg addSubview:lblNoticeName];
    
    _tfName = [[UITextField alloc] initWithFrame:CGRectMake(90, 38, viewBg.width - 100, 42)];
    _tfName.placeholder = @"请输入姓名";
    _tfName.font = [UIFont systemFontOfSize:14];
    _tfName.textColor = kColorWithHex(0x0d0e10);
    [viewBg addSubview:_tfName];
    
    UIView *viewLineOne = [[UIView alloc] initWithFrame:CGRectMake(10, 80, viewBg.width - 10, 1)];
    viewLineOne.backgroundColor = kColorWithHex(0xdbdbdb);
    [viewBg addSubview:viewLineOne];
    
    UILabel *lblNoticePhone = [[UILabel alloc] initWithFrame:CGRectMake(10, 81, 70, 42)];
    lblNoticePhone.textColor = kColorWithHex(0x666666);
    lblNoticePhone.font = [UIFont systemFontOfSize:14];
    lblNoticePhone.text = @"联系电话:";
    [viewBg addSubview:lblNoticePhone];
    
    _tfPhone = [[UITextField alloc] initWithFrame:CGRectMake(90, 81, viewBg.width - 100, 44)];
    _tfPhone.placeholder = @"请输入联系电话";
    _tfPhone.font = [UIFont systemFontOfSize:14];
    _tfPhone.textColor = kColorWithHex(0x0d0e10);
    [viewBg addSubview:_tfPhone];
    
    UIView *viewLineTwo = [[UIView alloc] initWithFrame:CGRectMake(10, 125, viewBg.width - 10, 1)];
    viewLineTwo.backgroundColor = kColorWithHex(0xdbdbdb);
    [viewBg addSubview:viewLineTwo];
    
    UIView *viewResult = [[UIView alloc] initWithFrame:CGRectMake(10, 136, viewBg.width - 20, 85)];
    viewResult.backgroundColor = kColorWithHex(0xf2f2f2);
    viewResult.layer.cornerRadius = 4;
    viewResult.layer.masksToBounds = YES;
    [viewBg addSubview:viewResult];
    
    _tvResult = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, viewResult.width - 20, viewResult.height - 20)];
    _tvResult.placeholder = @"在这里输入处理结果哦";
    _tvResult.placeholderColor = kColorWithHex(0x979797);
    _tvResult.placeholderLabel.font = [UIFont systemFontOfSize:16];
    _tvResult.font = [UIFont systemFontOfSize:14];
    _tvResult.textColor = kColorWithHex(0x0d0e10);
    _tvResult.backgroundColor = [UIColor clearColor];
    [viewResult addSubview:_tvResult];
    
    UIButton *btnSubmit = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnSubmit setTitle:@"提交" forState:UIControlStateNormal];
    [btnSubmit setTitleColor:kColorWithHex(0xffffff) forState:UIControlStateNormal];
    [btnSubmit setBackgroundColor:kColorWithHex(0x70be68)];
    btnSubmit.titleLabel.font = [UIFont systemFontOfSize:16];
    btnSubmit.layer.cornerRadius = 4;
    btnSubmit.layer.masksToBounds = YES;
    [btnSubmit addTarget:self action:@selector(btnSubmitClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnSubmit];
    [btnSubmit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.bottom.equalTo(self.view.mas_bottom).offset(-kScaleNum(112));
        make.size.mas_equalTo(CGSizeMake(kScaleNum(319), 48));
    }];
}
#pragma mark - BApplyForMoneySuccessViewDelegate
- (void)viewBtnOKClick{
    if (self.navigationController.viewControllers.count > 2) {
        UIViewController *vc = [self.navigationController.viewControllers objectAtIndexSafe:1];
        [self.navigationController popToViewController:vc animated:YES];
    }
}
#pragma mark - ZTimeOutOrderAlertDealViewDelegate
- (void)viewBtnOKClickAction{
    if (self.navigationController.viewControllers.count > 2) {
        UIViewController *vc = [self.navigationController.viewControllers objectAtIndexSafe:1];
        [self.navigationController popToViewController:vc animated:YES];
    }
}
#pragma mark - 交互事件
- (void)leftClick{
    ZTimeOutOrderAlertDealView *viewAlert = [[ZTimeOutOrderAlertDealView alloc] init];
    viewAlert.delegate = self;
    [viewAlert showView];
}
- (void)btnSubmitClickAction:(UIButton *)sender{
    NSString *nameStr = [_tfName.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    NSString *phoneStr = [_tfPhone.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    NSString *resultStr = [_tvResult.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    if (nameStr.length < 1) {
        ShowToastWithText(@"请输入姓名");
    }else if (![HFTools validateMobile:phoneStr]){
        ShowToastWithText(@"请检查手机号");
    }else if (resultStr.length < 1){
        ShowToastWithText(@"请输入处理结果");
    }else{
        NSMutableDictionary *param = [NSMutableDictionary dictionary];
        [param setObjectIfNotNil:self.orderID forKey:@"id"];
        [param setObjectIfNotNil:nameStr forKey:@"name"];
        [param setObjectIfNotNil:phoneStr forKey:@"phone"];
        [param setObjectIfNotNil:resultStr forKey:@"content"];
        [NetWorkTool POST:USER_FINISH_OVERTIME param:param success:^(id dic) {
            BApplyForMoneySuccessView *viewSuccess = [[BApplyForMoneySuccessView alloc] init];
            viewSuccess.delegate = self;
            [viewSuccess showView];
            [[NSNotificationCenter defaultCenter] postNotificationName:USER_DEAL_TIME_OUT_ORDER_SUCCESS object:nil];
        } other:^(id dic) {
            ShowToastWithText(dic[@"msg"]);
        } fail:^(NSError *error) {
            
        } needUser:YES];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
